package org.xiaodongwei.jvm.exe;

import tech.medivh.classpy.classfile.bytecode.Instruction;

import java.util.Iterator;

/**
 * JVM指令寄存器，用于指令执行迭代
 */
@SuppressWarnings("all")
public class JVMPcRegister implements Iterable<Instruction> {

    private JVMStack jvmStack;

    public JVMPcRegister(JVMStack stack) {
        this.jvmStack = stack;
    }

    @Override
    public Iterator<Instruction> iterator() {
        return new InstructionIter();
    }

    class InstructionIter implements Iterator<Instruction> {

        @Override
        public boolean hasNext() {
            return !jvmStack.isEmpty();
        }

        @Override
        public Instruction next() {
            JVMStackFrame topFrame = jvmStack.peek();
            return topFrame.getNextInstruction();
        }
    }
}
